class Solution
{
public:
    int searchInsert(vector<int>& nums, int target)
    {
        int n = nums.size() - 1;
        int left = 0, right = n;
        while (left < right)
        {
            int mid = left + (right - left) / 2;
            if (nums[mid] < target) left = mid + 1;
            else right = mid;
        }
        if (target > nums[left]) return left + 1;
        return left;
    }
};